package com.hy;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * <p>
 * User:Mr.Du
 * Date:2024/5/21
 * Time:9:37
 */
public class MaxAbsoluteSum {


    public int maxAbsoluteSum(int[] nums) {
        int res = 0, fMax = 0, fMin = 0;
        for (int num : nums) {
            fMax = Math.max(fMax, 0) + num;
            fMin = Math.min(fMin, 0) + num;
            res = Math.max(res, Math.max(fMax, -fMin));
        }
        return res;
    }
    public int maxAbsoluteSum1(int[] nums) {
        return Math.max(maxSubArray(nums, 1), maxSubArray(nums, -1));
    }

    public int maxSubArray(int[] nums, int x) {
        int res = 0;
        int sum = 0;
        for (int num : nums) {
            sum = Math.max(sum, 0) + num;
            res = Math.max(res, sum);
        }
        return res;
    }


}
